//
//  MyTableViewCell.m
//  SpeechRecognition
//
//  Created by 张云江 on 2019/10/12.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "MyTableViewCell.h"

@implementation MyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self initView];
    }
    return self;
}

- (void)initView
{
    UIImageView *imageView = [[UIImageView alloc] init];
    [self.contentView addSubview:imageView];
    imageView.sd_layout
    .centerYEqualToView(self.contentView)
    .leftSpaceToView(self.contentView, kRatio(19))
    .widthIs(kRatio(20))
    .heightEqualToWidth();
    _iconView = imageView;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = kUIColorFromRGB(0x000000);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont systemFontOfSize:kRatio(16)];
    [self.contentView addSubview:titleLabel];
    titleLabel.sd_layout
    .centerYEqualToView(self.contentView)
    .leftSpaceToView(imageView, kRatio(9))
    .heightIs(kRatio(16));
    [titleLabel setSingleLineAutoResizeWithMaxWidth:kScreenWidth];
    _titleLabel = titleLabel;
    
    arrowImage = [[UIImageView alloc] init];
    arrowImage.image = [UIImage imageNamed:@"My_07"];
    [self.contentView addSubview:arrowImage];
    arrowImage.sd_layout
    .centerYEqualToView(self.contentView)
    .rightSpaceToView(self.contentView, kRatio(14))
    .heightIs(kRatio(10))
    .widthIs(kRatio(6));
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = kUIColorFromRGB(0xD9D9D9);
    [self.contentView addSubview:lineView];
    lineView.sd_layout
    .topEqualToView(self.contentView)
    .leftSpaceToView(self.contentView, kRatio(20))
    .rightSpaceToView(self.contentView, kRatio(0))
    .heightIs(kRatio(.6));
    _lineView = lineView;
}

- (void)setIconName:(NSString *)iconName
{
    _iconName = iconName;
    
    self.iconView.image = [UIImage imageNamed:iconName];
}

- (void)setTitleName:(NSString *)titleName
{
    _titleName = titleName;
    
    self.titleLabel.text = titleName;
    if ([titleName isEqualToString:@"版本号"]) {
        arrowImage.hidden = YES;
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.textColor = kUIColorFromRGB(0x000000);
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont systemFontOfSize:kRatio(15)];
        titleLabel.text = app_Version;
        [self.contentView addSubview:titleLabel];
        titleLabel.sd_layout
        .centerYEqualToView(self.contentView)
        .rightSpaceToView(self.contentView, kRatio(20))
        .heightIs(kRatio(16));
        [titleLabel setSingleLineAutoResizeWithMaxWidth:kScreenWidth];
        
    } else if ([titleName isEqualToString:@"清除缓存"]) {
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.textColor = kUIColorFromRGB(0x000000);
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont systemFontOfSize:kRatio(15)];
        titleLabel.text = [NSString stringWithFormat:@"0M"];
        [self.contentView addSubview:titleLabel];
        titleLabel.sd_layout
        .centerYEqualToView(self.contentView)
        .rightSpaceToView(self.contentView, kRatio(30))
        .heightIs(kRatio(16));
        [titleLabel setSingleLineAutoResizeWithMaxWidth:kScreenWidth];
    }
}

- (void)setRow:(NSInteger)row
{
    _row = row;
    if (row == 0) {
        _lineView.hidden = YES;
    } else {
        _lineView.hidden = NO;
    }
}
@end
